<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		
		<script>
			var href="http://localhost:8080/sgcms/searchTradeGoods.jspx?categoryId=1&typeId=1&categoryId=1&q=&searchType=1";
			
			console.log(xiugaicanshu(href,"luo","22"));
			
			
			function xiugaicanshu(href,keyed,newvalue){
				var key2=keyed+"=";
				var resulr_url="";
				var newparam="";
				let url=href.substring(0,href.indexOf("?"));
				let strs=href.substring(href.indexOf("?")+1,href.length+1);
				let params=strs.split("&");
				
	        	var result = [];
		        for(var i=0;i<params.length;i++){
		           if(result.indexOf(params[i])==-1){
		              result.push(params[i])
		         	}
	    		}
		        resulr_url+=url+"?";
		        //key,value
		        result.forEach(function(item,index,array){
					let key=item.substring(0,item.indexOf("=")+1);
					let value=item.substring(item.indexOf("=")+1,item.length);
					if(key==key2){
						value=newvalue;
					}else{
						newparam=key2+newvalue;
					}
					resulr_url+=key+value+"&"
				});
				resulr_url=resulr_url+newparam;
				resulr_url=resulr_url.substring(0,resulr_url.length-1);
				
				return resulr_url;
			}
		</script>
		
	</body>
</html>
